package com.yyh.fanxing;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;
import java.util.TreeSet;

/*用Comparable接口对下列四位同学的成绩做降序排序，如果成绩一样，
那在成绩排序的基础上按照年龄由小到大排序。请正确指定泛型
（2）用Comparator实现按照姓名排序，请正确指定泛型
*/
public class Demo1 {
    public static void main(String[] args) {

    }
}
interface Comparable<T>{
    int compareTo(T o1, T o2);
}
class StudentComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {

        if (o1.getScore() > o2.getScore()){
            return 1;
        }else if (o1.getScore() < o2.getScore()){
            return -1;
        }else {
            if (o1.getAge() < o2.getAge()){
                return -1;
            }else if (o1.getAge() > o2.getAge()){
                return 1;
            }else {
                return 0;
            }
        }

    }
}
class Student{
    private String name;
    private int age;
    private double score;

    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Double.compare(student.score, score) == 0 && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age, score);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }
}
